package cn.yunyichina.provider.pay.service;

import cn.yunyichina.provider.framework.dubbo.service.HisifaceService;
import cn.yunyichina.provider.iface.entity.base.OrderExtVo;
import cn.yunyichina.provider.iface.entity.common.ResCommon;
import cn.yunyichina.provider.iface.entity.common.Response;
import cn.yunyichina.provider.iface.entity.hisiface.clinic.RefundClinicInsuranceVo;
import cn.yunyichina.provider.iface.entity.hisiface.clinic.SettleClinicInsuranceVo;
import cn.yunyichina.utils.convert.JsonUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;

@Service
public class InsuranceServiceImpl {
    static Logger log = LoggerFactory.getLogger(InsuranceServiceImpl.class);

    /**
     * 门诊医保结算 yyt.pay.insurance.mz.set
     *
     * @param data
     * @param sessionId
     * @param Object
     * @return
     */
    public Response setInsuranceMz(String data, String sessionId) {
        log.info("setInsuranceMz, data=" + data);
        Response response = new Response();
        SettleClinicInsuranceVo vo = JsonUtils.parseObject(data, SettleClinicInsuranceVo.class);
        log.info("setInsuranceMz, request="+ JSON.toJSONString(vo));
        ResCommon<Void> voidResponse = HisifaceService.getHisifaceClient().settleClinicInsurance(vo);
        log.info("setInsuranceMz, voidResponse=" + JSON.toJSONString(voidResponse));
        response.setResultCodeAndMessage(voidResponse.getResultCode(), voidResponse.getResultMessage());
        response.setResult(JsonUtils.toJsonString(voidResponse.getResult()));
        return response;
    }

    /**
     * 门诊医保退款 yyt.pay.insurance.mz.refund
     *
     * @param data
     * @param sessionId
     * @param Object
     * @return
     */
    public Response refundInsuranceMz(String data, String sessionId) {
        log.info("refundInsuranceMz, data=" + data);
        Response response = new Response();
        RefundClinicInsuranceVo vo = JsonUtils.parseObject(data, RefundClinicInsuranceVo.class);
        ResCommon<Void> voidResponse = HisifaceService.getHisifaceClient().refundClinicInsurance(vo);
        log.info("refundInsuranceMz, voidResponse=" + JSON.toJSONString(voidResponse));
        response.setResultCodeAndMessage(voidResponse.getResultCode(), voidResponse.getResultMessage());
        response.setResult(JsonUtils.toJsonString(voidResponse.getResult()));
        return response;
    }
}
